package com.mayihr.fx.three_;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Stage;

/**
 * www.javafxchina.net/blog/2015/04/doc02_label/
 * 1.标签图片、文字、字体、鼠标事件。
 */
public class L1_label extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        /*空标签*/
        Label label1 = new Label();
        /*带文本的标签*/
        Label label2 = new Label("Search");
        /*带文本和图标的标签*/
        Image image = new Image(getClass().getResourceAsStream("/three_/L1_label/labels.jpg"));
        final Label label3 = new Label("Search", new ImageView(image));

        label1.setText("Search");
        label1.setGraphic(new ImageView(image));
        label1.setTextFill(Color.web("#0076a3"));
//        label2.setGraphicTextGap(-10); //设置文本和图片之间的间距
        label1.setContentDisplay(ContentDisplay.BOTTOM);

        label1.setFont(new Font("Arial", 30));
        label2.setFont(new Font("Cambria", 32));

        label3.setText("A label that needs to be wrapped");
        label3.setWrapText(true);


        label2.setText("Values");
        label2.setFont(new Font("Cambria", 32));
        label2.setRotate(270);
        label2.setTranslateX(50);

         label3.setOnMouseEntered((MouseEvent e) ->{
             label3.setScaleX(1.5);
             label3.setScaleY(1.5);
         });

         label3.setOnMouseExited((MouseEvent e) ->{
             label3.setScaleX(1);
             label3.setScaleY(1);
         });
        StackPane stackPane = new StackPane();
//        stackPane.getChildren().add(label1);
//        stackPane.getChildren().add(label2);
//        stackPane.getChildren().add(label2);
        stackPane.getChildren().add(label3);
//        stackPane.getChildren().addAll(label1, label2, label3);
        Scene scene = new Scene(stackPane);
        primaryStage.setScene(scene);
        primaryStage.setTitle("Label-Test");
        primaryStage.show();
    }
}
